﻿using AutoMapper;
using AutoMapper.Configuration.Conventions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPF.Core
{
    public interface IAppMapper
    {
        IMapper Current { get; }

        IDestination Map<IDestination>(object source);
    }

    /// <summary>
    /// 实体模型映射服务
    /// </summary>
    public class AppMapper : IAppMapper
    {
        public AppMapper()
        {
            var config = new MapperConfiguration(config =>
            {
                var assemblys = AppDomain.CurrentDomain.GetAssemblies();
                config.AddMaps(assemblys);
            });
            Current = config.CreateMapper();
        }

        /// <summary>
        /// AutoMapper 内部转换接口
        /// </summary>
        public IMapper Current { get; set; }

        public IDestination Map<IDestination>(object source) => Current.Map<IDestination>(source);
    }
}
